n = int(input())
nums = list(map(int, input().split()))
ans = 0
for bit in range(32):
    cnt0 = 0
    cnt1 = 0
    index0 = 0  # 位0的下标和
    index1 = 0
    for i, num in enumerate(nums):
        if num & (1 << bit):
            cnt1 += 1
            index1 += i
            ans += (cnt0 * i - index0) * (1 << bit)
        else:
            cnt0 += 1
            index0 += i
            ans += (cnt1 * i - index1) * (1 << bit)
print(ans)
